package com.ratta.supernote.note.plugincore.api;


import android.graphics.Bitmap;
import android.graphics.Rect;

import androidx.lifecycle.MutableLiveData;

import com.ratta.supernote.note.plugincore.bean.ImageData;
import com.ratta.supernote.note.plugincore.bean.TrailsData;

/**
 * Note data cache interface
 * Used to cache note data for plugins, requires note main program to update this data in real time
 */
public abstract class NoteDataCacheApi {

    ImageData noteImageData = null;

    /**
     * Image change callback
     */
    public interface NoteImageCallback {
        /**
         * Image data changed
         */
        void onChange();

    }

    MutableLiveData<Boolean> isPluginStartActivity = new MutableLiveData<>(false);

    MutableLiveData<TrailsData> trailsData = new MutableLiveData<>();


    /**
     * Lasso selection area range
     */
    MutableLiveData<Rect> lassoRect = new MutableLiveData<>();

    /**
     * Lasso state
     * 0: Show, 1: Hide, 2: Completely remove
     */
    MutableLiveData<Integer> lassoState = new MutableLiveData<>();

    private static NoteDataCacheApi instance;

    public static NoteDataCacheApi getInstance() {
        return instance;
    }

    public static void init(NoteDataCacheApi noteDataCacheApi) {
        instance = noteDataCacheApi;
    }

    public ImageData getNoteImageData() {
        return noteImageData;
    }

    public void setNoteImageData(ImageData imageData) {
        noteImageData = imageData;
    }

    /**
     * Image change
     */
    public abstract void onNoteImageChange();


    /**
     * Add image callback
     */
    public abstract void addImageCallback(NoteImageCallback callback);

    public MutableLiveData<Boolean> getIsPluginStartActivity() {
        return isPluginStartActivity;
    }

    public MutableLiveData<TrailsData> getTrailsData() {
        return trailsData;
    }

    /**
     * Get lasso selection area range
     *
     * @return
     */
    public MutableLiveData<Rect> getLassoRect() {
        return lassoRect;
    }

    /**
     * @return Return lasso box state
     */
    public MutableLiveData<Integer> getLassoState() {
        return lassoState;
    }

    /**
     * Get current note path
     * @return
     */
    public abstract String getCurrentNotePath();
}
